<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {
	//空操作
	public function _empty(){
		header("HTTP/1.0 404 Not Found");
		$this->display('Public:404');
	}
	public function login(){
        $this->display();
    }
    
	/**
	*登录验证
	*/
    public function checkLogin(){
    	if(IS_AJAX){
			//接收AJAX的传值
			$username = I("post.username");
			$pwd = I("post.pwd");
			//判断是否有空值
			if(empty($username) || empty($pwd)){
				$data['status'] = -1;
				$data['info'] = "账户或密码不能为空";
				$this->ajaxReturn($data);exit();
			}
			//查询是否有此账户
			$where['username'] = $username;
			$re = M("Admin")->where($where)->find();
			if($re['password'] != md5($pwd)){
				$data['status'] = -2;
				$data['info'] = "账户或密码不正确";
				$this->ajaxReturn($data);exit();
			}
			//判断账号密码正确封存session
			$_SESSION['ADMIN_KEY'] = $re['admin_id'];
			
			//返回正确信息
			$data['status'] = 1;
			$data['info'] = "登录成功";
			$this->ajaxReturn($data);exit();	
		}
    }

    //登出
    public function loginout(){
    	//销毁session
		$_SESSION['ADMIN_KEY'] = null;
		//跳转到登录界面
		$this->redirect('Login/login');
    }
     
}